package com.climber.android.lib_share.platform.wechat

import cn.sharesdk.framework.Platform
import cn.sharesdk.framework.ShareSDK
import cn.sharesdk.wechat.favorite.WechatFavorite
import com.climber.android.lib_share.entity.ShareConfig
import com.climber.android.lib_share.sensor.MyShareActionListener
import com.climber.android.lib_share.sensor.ShareAction
import com.climber.android.lib_share.sensor.ShareResultCallBack
import com.mob.MobSDK

/**
 * Created by Mikes at 2020-03-19 16:25
 * 微信朋友圈分享
 */
class WeChatFavouriteShare internal constructor(val shareConfig : ShareConfig, val builder: ShareResultCallBack.Builder.()->Unit): ShareAction {
    override fun shareMiniProgram() {
    }

    // 分享纯文字
    override fun shareText() {
        val shareParams = Platform.ShareParams()
        shareParams.shareType = Platform.SHARE_TEXT
        shareParams.title = shareConfig.title
        shareParams.text = shareConfig.text

        val platform = ShareSDK.getPlatform(WechatFavorite.NAME)
        platform.platformActionListener = MyShareActionListener(builder)

        //启动分享
        platform.share(shareParams)
    }

    // 分享图片
    override fun shareImage(){
        val shareParams = Platform.ShareParams()
        shareParams.shareType = Platform.SHARE_IMAGE
        shareParams.text = shareConfig.text
        shareParams.imageUrl = shareConfig.imageUrl ?: ""
        shareParams.imagePath = shareConfig.imagePath ?: ""
        shareParams.imageData = shareConfig.imageBmp

        val platform = ShareSDK.getPlatform(WechatFavorite.NAME)
        platform.platformActionListener = MyShareActionListener(builder)

        //启动分享
        platform.share(shareParams)
    }

    override fun shareMusic(){
        val shareParams = Platform.ShareParams()
        shareParams.shareType = Platform.SHARE_MUSIC
        shareParams.title = shareConfig.title
        shareParams.text = shareConfig.text
        shareParams.imagePath = shareConfig.imagePath ?: ""
        shareParams.imageUrl = shareConfig.imageUrl ?: ""
        shareParams.musicUrl = shareConfig.musicUrl ?: ""
        shareParams.url = shareConfig.url ?: ""

        val platform = ShareSDK.getPlatform(WechatFavorite.NAME)
        platform.platformActionListener = MyShareActionListener(builder)

        //启动分享
        platform.share(shareParams)
    }

    override fun shareVideo(){
        val shareParams = Platform.ShareParams()
        shareParams.shareType = Platform.SHARE_VIDEO
        shareParams.title = shareConfig.title
        shareParams.text = shareConfig.text
        shareParams.imageUrl = shareConfig.imageUrl ?: ""
        shareParams.imagePath = shareConfig.imagePath ?: ""
        shareParams.url = shareConfig.url ?: ""

        val platform = ShareSDK.getPlatform(WechatFavorite.NAME)
        platform.platformActionListener = MyShareActionListener(builder)

        //启动分享
        platform.share(shareParams)
    }

    override fun shareWebPage(){
        val platform = Platform.ShareParams()
        platform.shareType = Platform.SHARE_WEBPAGE
        platform.title = shareConfig.title
        platform.text = shareConfig.text
        platform.url = shareConfig.url ?: ""
        platform.imageUrl = shareConfig.imageUrl ?: ""
        platform.imagePath = shareConfig.imagePath ?: ""

        val wechat = ShareSDK.getPlatform(WechatFavorite.NAME)
        wechat.platformActionListener = MyShareActionListener(builder)

        //启动分享
        wechat.share(platform)
    }

    override fun shareFile() {
        val platform = Platform.ShareParams()
        platform.shareType = Platform.SHARE_FILE
        platform.title = shareConfig.title
        platform.text = shareConfig.text
        platform.imageUrl = shareConfig.imageUrl ?: ""
        platform.filePath = shareConfig.filePath ?: ""
        platform.imagePath = shareConfig.imagePath ?: ""

        val wechat = ShareSDK.getPlatform(WechatFavorite.NAME)
        wechat.platformActionListener = MyShareActionListener(builder)

        //启动分享
        wechat.share(platform)
    }
}